<import file="block/common.html" name="url"/>
<div class="layui-fluid">
	<div class="layui-row layui-col-space15">
		<div class="layui-col-md12">
			<!-- <script type="text/html" id="toolbarAE">
            <div class="layui-btn-container">
			<?php echo sysrolTF("notice_addview")?'<button class="layui-btn layui-btn-sm data-add-btn">添加附件</button>':''; ?> 
            </div>
        </script> -->

			<table class="layui-hide" id="currentTableId" lay-data="{id: 'idReload'}" lay-filter="currentTableFilter">
			</table>
			<script type="text/html" id="sizeTpl">{{ getfilesize(d.size) }}</script>

			<!-- <script type="text/html" id="currentTableBar">
			<?php echo sysrolTF("notice_del")?'<a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>':''; ?> 
			</script> -->
		</div>
	</div>
</div>
<script>
	layui.use('table', function () {
		var table = layui.table,
			$ = layui.jquery;
		   
		table.render({
			elem: '#currentTableId',
			url: '<{caUrl("attment","index")}>&list_json',
			toolbar: '#toolbarAE',
			defaultToolbar: ['filter', 'exports', 'print', {
				title: '提示',
				layEvent: 'LAYTABLE_TIPS',
				icon: 'layui-icon-tips'
			}],
			page: {
				layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
				//,curr: 5 //设定初始在第 5 页
				, groups: 1 //只显示 1 个连续页码
				, first: false //不显示首页
				, last: false //不显示尾页
			},
			cols: [[
				//{type: "checkbox", width: 50, fixed: "left"},
				{ field: 'attid', width: 80, title: 'ID', sort: true },
				{ field: 'userid', width: 110, title: '用户ID', sort: true},
				{ field: 'atturl',title: '路径' },
				{ field: 'priname', title: '原始文件名' },
				{ field: 'ext', width: 200, title: '尾缀_类型', sort: true },
				{ field: 'size',width: 200, title: '文件大小', sort: true, templet: '#sizeTpl'},
			]],
			limits: [10, 15, 20, 25, 50, 100],
			limit: 15,
			page: true
		});


		// 监听添加操作
		$(".data-add-btn").on("click", function () {
			loadMain('<{caUrl("notice","addview")}>');
			return false;
		});
		// 监听删除操作
		$(".data-delete-btn").on("click", function () {
			var checkStatus = table.checkStatus('currentTableId')
				, data = checkStatus.data;
			layer.alert(JSON.stringify(data));
		});



		table.on('tool(currentTableFilter)', function (obj) {
			var data = obj.data;
			if (obj.event === 'edit') {
				loadMain('<{caUrl("attment","editview")}>&id=' + data.id);
				return false;
			} else if (obj.event === 'delete') {
				layer.confirm('真的删除么', function (index) {
					$.post('<{caUrl("attment","del")}>', data, function (res) {
						if (res.status == 1) {
							layer.msg(res.info, { icon: 1, time: 1000 }, function () {
								obj.del();
								layer.close(index);
							});
						} else {
							layer.msg(res.info, { icon: 2, anim: 6, time: 5000 });
						}
					});
				});
			}
		});
	});

	function getfilesize(size) {
        if (!size)
            return "";
 
        var num = 1024.00; //byte
 
        if (size < num)
            return size + " byte";
        if (size < Math.pow(num, 2))
            return (size / num).toFixed(2) + " KB"; //kb
        if (size < Math.pow(num, 3))
            return (size / Math.pow(num, 2)).toFixed(2) + " MB"; //M
        if (size < Math.pow(num, 4))
            return (size / Math.pow(num, 3)).toFixed(2) + " GB"; //G
        return (size / Math.pow(num, 4)).toFixed(2) + "TB"; //T
    }
</script>